home *** CD-ROM | disk | FTP | other *** search
- /**
- AEFX_FXwinUI.c
-
- Part of the Adobe After Effects 3.1 SDK
- Copyright (c)1993-96, Adobe Systems Inc, All Rights Reserved.
-
- Revision History
- 1.0, created by dmw
- **/
-
- #include "AE_Effect.h"
- #include "AE_EffectCB.h"
- #include "AE_EffectUI.h"
-
- #include "AEFX_FXwin.h"
- #include <math.h>
-
-
- Boolean CreateOffscreenBitMap (GWorldPtr *newOffscreen, short depth, Rect *inBounds)
- {
- GWorldPtr oldPort;
- GDHandle oldDev;
- OSErr err;
- GWorldPtr newWorld;
-
- GetGWorld(&oldPort, &oldDev);
-
- err = NewGWorld(&newWorld, depth, inBounds, NULL, NULL, 0);
- if (!err) {
- LockPixels(newWorld->portPixMap);
- SetGWorld(newWorld, NULL);
- EraseRect(inBounds);
- UnlockPixels(newWorld->portPixMap);
- *newOffscreen = newWorld;
- } else {
- *newOffscreen = NULL;
- }
-
- SetGWorld(oldPort, oldDev);
- if (err) return FALSE;
- else return TRUE;
-
- } // CreateOffscreenBitMap
-
-
- void DestroyOffscreenBitMap( GWorldPtr oldOffscreen )
- {
- DisposeGWorld((GWorldPtr)oldOffscreen);
-
- } // DestroyOffscreenBitMap
-
-
- static PolyHandle PolyFromParams (PF_ParamDef *params[])
- {
- PolyHandle temp;
- long min, max, soft_min, soft_max;
-
- min = params[EX_BLACK]->u.sd.value;
- max = params[EX_WHITE]->u.sd.value;
- soft_min = params[EX_BLACK_FUZ]->u.sd.value;
- soft_max = params[EX_WHITE_FUZ]->u.sd.value;
-
- temp = OpenPoly();
- if (temp) {
- MoveTo(min - soft_min, EX_WEDGE_HEIGHT - 2);
- LineTo(min, 1);
- LineTo(max - 1, 1);
- LineTo(max + soft_max - 1 , EX_WEDGE_HEIGHT - 2);
- LineTo(min - soft_min, EX_WEDGE_HEIGHT - 2);
- ClosePoly();
- }
-
- return temp;
- }
-
-
- static PolyHandle PolyFromParamsInv (PF_ParamDef *params[], long which)
- {
- PolyHandle temp;
- long min, max, soft_min, soft_max;
-
- min = params[EX_BLACK]->u.sd.value;
- max = params[EX_WHITE]->u.sd.value;
- soft_min = params[EX_BLACK_FUZ]->u.sd.value;
- soft_max = params[EX_WHITE_FUZ]->u.sd.value;
-
- temp = OpenPoly();
- if (temp && which) {
- MoveTo (0, 1);
- LineTo(min, 1);
- LineTo(min - soft_min, EX_WEDGE_HEIGHT - 2);
- LineTo(0, EX_WEDGE_HEIGHT - 2);
- LineTo(0, 1);
- ClosePoly();
-
- } else if (temp) {
- MoveTo(255, 1);
- LineTo(255, EX_WEDGE_HEIGHT - 2);
- LineTo(max + soft_max, EX_WEDGE_HEIGHT - 2);
- LineTo(max, 1);
- LineTo(255, 1);
- ClosePoly();
- }
-
- return temp;
- }
-
-
- static PF_Err DrawHist (
- PF_ParamDef *params[],
- EX_Globals *globals )
- {
- PF_Err err = PF_Err_NONE;
- GWorldPtr saveWorld;
- GDHandle saveDevice;
- GWorldPtr offscreen = globals->graphbits;
- long y;
- long max_hist;
- long *histogram;
- long scale_hist[256];
- double scale;
-
- histogram = globals->hist;
- max_hist = globals->hist[0];
-
- for (y=0; y<256; y++) {
- if (histogram[y] > max_hist) max_hist = histogram[y];
- }
-
- scale = ((double)EX_HIST_HEIGHT/(double)max_hist);
-
- for (y=0; y<256; y++) {
- scale_hist[y] = scale * histogram[y];
- }
-
-
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld(offscreen, NULL);
-
- EraseRect(&globals->offRect);
- if (globals->freshHist) {
- for (y=0; y<256; y++) {
- MoveTo(y, EX_HIST_HEIGHT);
- LineTo(y, EX_HIST_HEIGHT-scale_hist[y]);
- }
- } else {
- MoveTo(0, 0);
- LineTo(EX_HIST_WIDTH, EX_HIST_HEIGHT);
-
- MoveTo(0, EX_HIST_HEIGHT);
- LineTo(EX_HIST_WIDTH, 0);
- FrameRect(&globals->offRect);
- }
-
- SetGWorld(saveWorld, saveDevice);
-
- return err;
- }
-
-
- static void GetHandleBox (
- long which,
- PF_ParamDef *params[],
- Rect *box )
- {
- long min, max, soft_min, soft_max;
-
- long hi, lo;
-
- min = params[EX_BLACK]->u.sd.value;
- max = params[EX_WHITE]->u.sd.value;
- soft_min = params[EX_BLACK_FUZ]->u.sd.value;
- soft_max = params[EX_WHITE_FUZ]->u.sd.value;
-
- SetRect(box, -2, -2, 2, 2);
-
- if (FALSE && params[EX_INVERT]->u.pd.value) {
- lo = EX_WEDGE_HEIGHT - 2;
- hi = 1;
- } else {
- hi = EX_WEDGE_HEIGHT - 2;
- lo = 1;
- }
-
- switch (which) {
- case 2:
- OffsetRect(box, min - soft_min, hi);
- break;
-
- case 3:
- OffsetRect(box, max + soft_max - 1 , hi);
- break;
-
- case 0:
- OffsetRect(box, min, lo);
- break;
-
- case 1:
- OffsetRect(box, max - 1, lo);
- break;
- }
- }
-
-
- static PF_Err DrawPoly (
- PF_InData *in_data,
- PF_ParamDef *params[],
- EX_Globals *globals )
- {
- PF_Err err = PF_Err_NONE;
- PolyHandle poly;
- Rect box;
- GWorldPtr saveWorld;
- GDHandle saveDevice;
- GWorldPtr offscreen = globals->wedgebits;
- long i;
-
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld(offscreen, NULL);
-
- EraseRect(&globals->wedgeRect);
- if (params[EX_INVERT]->u.pd.value) {
- poly = PolyFromParamsInv(params, 1);
- FillPoly(poly, &in_data->qd_globals->gray);
- FramePoly(poly);
- KillPoly(poly);
-
- poly = PolyFromParamsInv(params, 0);
- FillPoly(poly, &in_data->qd_globals->gray);
- FramePoly(poly);
- KillPoly(poly);
-
- } else {
- poly = PolyFromParams(params);
- FillPoly(poly, &in_data->qd_globals->gray);
- FramePoly(poly);
- KillPoly(poly);
- }
-
- // ltrb
-
- for (i=0; i<4; i++) {
- GetHandleBox(i, params, &box);
- InvertRect(&box);
- }
-
- SetGWorld(saveWorld, saveDevice);
- return err;
-
- }
-
-
- static void GetWedgeBlitRect (
- PF_ParamDef *params[],
- PF_EventExtra *event_extra,
- Rect *wedge )
- {
- *wedge = event_extra->effect_win.current_frame;
- wedge->right = wedge->left + EX_HIST_WIDTH;
- wedge->top += EX_HIST_HEIGHT + 10;
- wedge->bottom = wedge->top + EX_WEDGE_HEIGHT;
- }
-
-
- static void GetWedgeHitRect (
- PF_ParamDef *params[],
- PF_EventExtra *event_extra,
- Rect *wedge )
- {
- short left_in, right_in;
-
- left_in = params[EX_BLACK]->u.sd.value - params[EX_BLACK_FUZ]->u.sd.value;
- if (left_in < 0) left_in = 0; else if (left_in > 255) left_in = 255;
-
- right_in = params[EX_WHITE]->u.sd.value + params[EX_WHITE_FUZ]->u.sd.value;
-
- right_in = 255 - right_in;
-
- if (right_in < 0) right_in = 0; else if (right_in > 255) right_in = 255;
- GetWedgeBlitRect(params, event_extra, wedge);
-
- wedge->left += left_in;
- wedge->right -= right_in;
- }
-
- static PF_Err DrawEvent (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output,
- PF_EventExtra *event_extra,
- Boolean erase )
- {
- PF_Err err = PF_Err_NONE;
- EX_Globals **globH;
- EX_Globals *globP;
- Rect offscreen, preview, cur_frame;
- GrafPtr dp = (*(event_extra->contextH))->cgrafptr;
- GWorldPtr saveWorld;
- GDHandle saveDevice;
- PixMapHandle pixBase;
- Rect er_rect;
-
- // stuff params into globals -- we need amount & type
-
- if ((*event_extra->contextH)->w_type == PF_Window_EFFECT) {
- if (event_extra->effect_win.area == PF_EA_CONTROL) {
-
- cur_frame = event_extra->effect_win.current_frame;
- if (erase) EraseRect(&cur_frame);
- GetGWorld(&saveWorld, &saveDevice);
-
- globH = (EX_Globals **)in_data->sequence_data;
- globP = *(globH);
- offscreen = globP->offRect;
-
- preview.top = event_extra->effect_win.current_frame.top;
- preview.left = event_extra->effect_win.current_frame.left;
- preview.right = preview.left + EX_HIST_WIDTH;
- preview.bottom = preview.top + EX_HIST_HEIGHT;
-
- // ltrb
-
- DrawHist(params, globP);
-
- DrawPoly(in_data, params, globP);
-
- if (globP->magic == EX_MAGIC) {
- pixBase = GetGWorldPixMap(globP->graphbits);
- if (LockPixels(pixBase)) {
- er_rect = cur_frame;
- er_rect.left = preview.right;
- er_rect.bottom = preview.bottom;
- EraseRect(&er_rect);
- CopyBits((BitMap*)*pixBase, &dp->portBits,
- &offscreen, &preview, srcCopy, 0L);
-
- UnlockPixels(pixBase);
- }
-
- pixBase = GetGWorldPixMap(globP->wedgebits);
- if (LockPixels(pixBase)) {
- er_rect = cur_frame;
- er_rect.left = preview.right;
- er_rect.bottom = preview.bottom;
- offscreen = globP->wedgeRect;
- EraseRect(&er_rect);
-
- GetWedgeBlitRect(params, event_extra, &preview);
-
- CopyBits((BitMap*)*pixBase, &dp->portBits,
- &offscreen, &preview, srcCopy, 0L);
-
- UnlockPixels(pixBase);
- }
-
- } else {
- out_data->out_flags |= PF_OutFlag_DISPLAY_ERROR_MESSAGE;
- PF_SPRINTF(out_data->return_msg, "Magic failed in Draw Event.");
- err = PF_Err_BAD_CALLBACK_PARAM;
- }
-
- SetGWorld(saveWorld, saveDevice);
- }
- }
-
- return err;
- }
-
-
- static PF_Err NewContext (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output,
- PF_EventExtra *event_extra )
- {
- PF_Err err = PF_Err_NONE;
-
- return err;
- }
-
-
- static PF_Err MyInfoReport (
- PF_EventExtra *event_extra,
- char *str1,
- char *str2 )
- {
- PF_Err err = PF_Err_NONE;
- GWorldPtr saveWorld;
- GDHandle saveDevice;
-
- PF_Err (*infotext)(void *refcon, char *text1, char *text2);
- void *refcon;
-
- refcon = event_extra->cbs.refcon;
- infotext = event_extra->cbs.info_draw_text;
-
- GetGWorld(&saveWorld, &saveDevice);
-
- (*infotext)(refcon, str1, str2);
-
- SetGWorld(saveWorld, saveDevice);
-
- return err;
- }
-
-
- static Boolean DoClickWedge (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output,
- PF_EventExtra *event_extra )
- {
- Rect wedge_hit;
- Point click_pt;
- Boolean did_click = FALSE;
-
- GetWedgeHitRect(params, event_extra, &wedge_hit);
- click_pt = event_extra->u.do_click.screen_point;
-
- if (PtInRect(click_pt, &wedge_hit)) {
- did_click = TRUE;
- event_extra->u.do_click.send_drag = TRUE;
- event_extra->u.do_click.continue_refcon[0] = EX_Drag_WEDGE;
- event_extra->u.do_click.continue_refcon[1] = click_pt.h;
- event_extra->u.do_click.continue_refcon[2] = params[EX_BLACK]->u.sd.value;
- event_extra->u.do_click.continue_refcon[3] = params[EX_WHITE]->u.sd.value;
- }
-
- return did_click;
- }
-
-
- static void DoDragWedge (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output,
- PF_EventExtra *event_extra )
- {
- Point click_pt;
- short dx;
- long black, white;
-
- click_pt = event_extra->u.do_click.screen_point;
- dx = click_pt.h - event_extra->u.do_click.continue_refcon[1];
-
- event_extra->u.do_click.continue_refcon[1] = click_pt.h;
-
- event_extra->u.do_click.continue_refcon[2] += dx;
- event_extra->u.do_click.continue_refcon[3] += dx;
-
- black = event_extra->u.do_click.continue_refcon[2];
- white = event_extra->u.do_click.continue_refcon[3];
-
- if (black < 0) {
- params[EX_BLACK]->u.sd.value = 0;
- params[EX_WHITE]->u.sd.value = white - black;
- } else if (white > 255) {
- params[EX_BLACK]->u.sd.value = 255 - white + black;
- params[EX_WHITE]->u.sd.value = 255;
- } else {
- params[EX_BLACK]->u.sd.value = black;
- params[EX_WHITE]->u.sd.value = white;
- }
- DrawEvent(in_data, out_data, params, output, event_extra, FALSE);
- params[EX_BLACK]->changed = TRUE;
- params[EX_WHITE]->changed = TRUE;
-
- event_extra->evt_out_flags |= PF_EO_HANDLED_EVENT;
- }
-
-
- static Boolean DoClickHandles (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output,
- PF_EventExtra *event_extra )
- {
- Rect box_hit;
- Rect preview;
- Point click_pt, old_pt, mouse_pt;
- short dx_orig, dx_last;
- Boolean did_click = FALSE;
- long i;
- long orig_value;
-
- GetWedgeBlitRect(params, event_extra, &preview);
-
- for (i=0; i<4; i++) {
- GetHandleBox(i, params, &box_hit);
- OffsetRect(&box_hit, preview.left, preview.top);
- InsetRect(&box_hit, -2, -2);
- click_pt = old_pt = event_extra->u.do_click.screen_point;
-
- if (PtInRect(click_pt, &box_hit)) {
- orig_value = params[EX_BLACK + i]->u.sd.value;
-
- while (StillDown()) {
- GetMouse(&mouse_pt);
- dx_orig = mouse_pt.h - click_pt.h;
- if (mouse_pt.h < 0 || mouse_pt.h > (260 + event_extra->effect_win.current_frame.left)) {
- dx_last = 0;
- } else {
- dx_last = mouse_pt.h - old_pt.h;
- }
-
- if (dx_last) {
- switch (i) {
- case 0: // ex_black
- if ((dx_orig + orig_value) < 0) {
- params[EX_BLACK]->u.sd.value = 0;
- } else if ((dx_orig + orig_value) >= params[EX_WHITE]->u.sd.value) {
- params[EX_BLACK]->u.sd.value = params[EX_WHITE]->u.sd.value - 1;
- } else {
- params[EX_BLACK]->u.sd.value = dx_orig + orig_value;
- }
-
- break;
-
- case 1: // ex_white
- if ((dx_orig + orig_value) > 255) {
- params[EX_WHITE]->u.sd.value = 255;
- } else if ((dx_orig + orig_value) <= params[EX_BLACK]->u.sd.value) {
- params[EX_WHITE]->u.sd.value = params[EX_BLACK]->u.sd.value + 1;
- } else {
- params[EX_WHITE]->u.sd.value = dx_orig + orig_value;
- }
-
- break;
-
- case 2: // black soft
- dx_orig = -dx_orig;
- if ((dx_orig + orig_value) < 0) {
- params[EX_BLACK_FUZ]->u.sd.value = 0;
- } else {
- params[EX_BLACK_FUZ]->u.sd.value = dx_orig + orig_value;
- }
-
- break;
-
- case 3: // white soft
- if ((dx_orig + orig_value) < 0) {
- params[EX_WHITE_FUZ]->u.sd.value = 0;
- } else {
- params[EX_WHITE_FUZ]->u.sd.value = dx_orig + orig_value;
- }
- break;
- }
- }
- params[i + EX_BLACK]->changed = TRUE;
-
-
- DrawEvent(in_data, out_data, params, output, event_extra, FALSE);
- did_click = TRUE;
- old_pt = mouse_pt;
- }
- }
- if (did_click) break;
- }
-
- return did_click;
- }
-
-
- static PF_Err DoClick (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output,
- PF_EventExtra *event_extra )
- {
- PF_Err err = PF_Err_NONE;
- PF_ContextH contextH = event_extra->contextH;
-
- if ((*contextH)->w_type == PF_Window_EFFECT) {
-
- if (event_extra->effect_win.area == PF_EA_CONTROL) {
-
- if (DoClickHandles(in_data, out_data, params, output, event_extra)) {
- event_extra->evt_out_flags |= PF_EO_HANDLED_EVENT;
- } else if (DoClickWedge(in_data, out_data, params, output, event_extra)) {
- event_extra->evt_out_flags |= PF_EO_HANDLED_EVENT;
- }
-
- }
-
- }
-
- return err;
- }
-
-
- static PF_Err DoDrag (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output,
- PF_EventExtra *event_extra )
- {
- PF_Err err = PF_Err_NONE;
- PF_ContextH contextH = event_extra->contextH;
-
- if ((*contextH)->w_type == PF_Window_EFFECT) {
-
- if (event_extra->effect_win.area == PF_EA_CONTROL) {
- if (event_extra->u.do_click.continue_refcon[0] == EX_Drag_WEDGE)
- DoDragWedge(in_data, out_data, params, output, event_extra);
- }
- }
-
- return err;
- }
-
-
- PF_Err HandleEvent (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output,
- PF_EventExtra *event_extra )
- {
- PF_Err err = PF_Err_NONE;
-
- if (in_data->sequence_data == NULL &&
- (event_extra->e_type == PF_Event_DO_CLICK ||
- event_extra->e_type == PF_Event_DRAW)) {
- err = SequenceResetup(in_data, out_data, params, output);
- if (!err) in_data->sequence_data = out_data->sequence_data;
- }
-
- switch (event_extra->e_type) {
-
- case PF_Event_NEW_CONTEXT:
- NewContext(in_data, out_data, params, output, event_extra);
- break;
-
- case PF_Event_ACTIVATE:
- break;
-
- case PF_Event_DO_CLICK:
- DoClick(in_data, out_data, params, output, event_extra);
- break;
-
- case PF_Event_DRAG:
- // right now, drag events are only sent for the wedge -> need to support drag for
- // the other handles
-
- DoDrag(in_data, out_data, params, output, event_extra);
- break;
-
- case PF_Event_DRAW:
- DrawEvent(in_data, out_data, params, output, event_extra, TRUE);
- break;
-
- case PF_Event_DEACTIVATE:
- break;
-
- case PF_Event_CLOSE_CONTEXT:
- break;
-
- case PF_Event_IDLE:
- break;
-
- default:
- break;
-
- }
-
- return err;
- }
-